<?php
require_once ('../coupon/common.php');

//个人测试号
$appid = 'wxd17a3baf67b5eb59';
$secret = '53493ffae58f62fe215cc3925ccb57eb';
//xb测试号
// $appid = 'wx5788137027e155d5';
// $appsecret = '6a3a12f21af7e6770169e2cdb511f482';
$code = $_GET["code"];    //通过该code获取access_token

//第一步:取全局access_token,改为使用全局的common中获取
//$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$secret";
$access_token = get_access_token();

 
//第二步:取得openid
$oauth2Url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=$appid&secret=$secret&code=$code&grant_type=authorization_code";
$oauth2 = getJson($oauth2Url);
  
//第三步:根据全局access_token和openid查询用户信息  
//$access_token = $token["access_token"];
$openid = $oauth2['openid'];  
$get_user_info_url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=$access_token&openid=$openid&lang=zh_CN";
$userinfo = getJson($get_user_info_url);
 
//打印用户信息
echo '<pre>';
print_r($userinfo);

